package com.meichis.yndms.room.dao;


import androidx.room.*;

import com.meichis.yndms.model.DicDataItem;

import java.util.List;

import io.reactivex.Flowable;

@Dao
public interface DicDataItemDao {
    @Query("SELECT * FROM DicDataItem")
    Flowable<List<DicDataItem>> findAll();

    @Query("SELECT * FROM DicDataItem WHERE ID=:id")
    Flowable<DicDataItem> find(int id);

    @Query("SELECT * FROM DicDataItem WHERE DicTableName=:dicTableName")
    List<DicDataItem> find(String dicTableName);

    @Query("SELECT * FROM DicDataItem WHERE DicTableName=:dicTableName and (Remark='' OR Remark=:remark)")
    List<DicDataItem> find(String dicTableName, String remark);

    @Query("DELETE FROM DicDataItem")
    int deleteAll();

    @Query("DELETE FROM DicDataItem WHERE DicTableName=:dicTableName")
    int delete(String dicTableName);

    @Delete
    int delete(DicDataItem... DicDataItems);

    @Update
    int update(DicDataItem... DicDataItems);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long[] insertAll(List<DicDataItem> list);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    long[] insert(DicDataItem... DicDataItems);

    @Query("DELETE FROM DicDataItem WHERE DicTableName NOT IN (:dicTableNames)")
    int deleteNotIn(String[] dicTableNames);

    @Query("SELECT * FROM DicDataItem WHERE ID IN(:ids) AND DicTableName=:dicTableName")
    List<DicDataItem> findByIds(String[] ids, String dicTableName);
}
